import streamlit as st
import pandas as pd
import numpy as np

import time
from sklearn.preprocessing import LabelEncoder

# classes

labelencoder = LabelEncoder()

def result():
    with st.spinner ('Wait...'):
        time.sleep(2)
    return st.success('You can sell a car for ', icon="🔥")

def submit():
    line = [bmt, w, tr, hp1, hp2, ec1, ec2, rg]
    columns = ['bmt','w','tr','hp1','hp2','ec1','ec2','rg']
    submit = pd.DataFrame(line, columns)
    submit.transpose().to_csv('./datasets/submitted.csv', index = False)
    # submit.bmt = labelencoder.fit_transform(submit.bmt)
    result()


# body

st.title('Predicting the cost of selling your car in the UAE')

st.header('''It's a simple car price prediction model''')

'---'

df = pd.read_csv('./datasets/clear_data.csv')

col1, col2 = st.columns(2)

with col2:
    st.image('./imgs/car.png', width=480)

with col1:

    bmt = st.selectbox('Write your car name here :point_down:', df.brand_model_trim.unique())

    w = st.checkbox('Warranty', True)

    tr = st.checkbox('Manual transmission', True)

    hp1, hp2 = st.slider('Range of horsepower', df.hp1.min(), df.hp2.max(), (df.hp1.min(), df.hp2.min()), 100.0)

    ec1, ec2 = st.slider('Range of engine capacity', df.ec1.min(), df.ec2.max(), (df.ec1.min(), df.ec2.min()), 100.0)

    rg = st.selectbox('Region of sale', df.area_name.unique())
    st.write(hp1, hp2)

    st.button('Submit', on_click=submit)